<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      .box {
        width: 300px;
        height: 200px;
        background-color: rgb(199, 113, 173);
        margin: 10px 10px;
        border: 1px solid transparent;
        position: relative;
        /* position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%,-50%);
            transition: all 1s; */
      }
      .son {
        width: 100px;
        height: 100px;
        background-color: aqua;
        margin-left: 15px;
        margin-top: 10px;
      }
      .w {
        width: 100px;
        height: 100px;
        background-color: aqua;
        padding: 10px;
        border: 10 solid transparent;
      }
    </style>
  </head>
  <body>
    <div class="box">
      <div class="son"></div>
    </div>

    <div class="w"></div>

    <script>
      let div = document.querySelector(".box");
      let son = document.querySelector(".son");
      let w = document.querySelector(".w");
      //获取元素在浏览器的高度
      console.log(div.offsetTop);
      //获取元素在浏览器的左侧位置
      console.log(div.offsetLeft);
      //如果父元素有定位就返回父元素，没有定位就返回body
      console.log(son.offsetParent);
      console.log(son.offsetTop);
      console.log(son.offsetLeft);
      console.log(w.offsetWidth);
      console.log(w.offsetWidth);
    </script>
  </body>
</html>
